home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / misc / amigem.lha / amigem / exec / devices.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-19  |  3.1 KB  |  129 lines

  1. #include <exec/execbase.h>
  2. #include <exec/errors.h>
  3. #include <clib/_exec.h>
  4.  
  5. #include <amigem/fd_lib.h>
  6. #define LIBBASE struct ExecBase *SysBase
  7.  
  8. FC3(1,void,Dev_Open,A6,struct IORequest *iob,A1,ULONG unitnum,D0,ULONG flags,D1)
  9. ;
  10. FC1(2,BPTR,Dev_Close,A6,struct IORequest *iob,A1)
  11. ;
  12. FC0(3,BPTR,Dev_Expunge,A6)
  13. ;
  14. FC1(5,void,Dev_BeginIO,A6,struct IORequest *iob,A1)
  15. ;
  16. FC1(6,ULONG,Dev_AbortIO,A6,struct IORequest *iob,A1)
  17. ;
  18.  
  19. FD1(72,void,AddDevice,struct Device *device,A1)
  20. {
  21.   Forbid();
  22.     Enqueue(&SysBase->DeviceList,&device->dd_Library.lib_Node);
  23.   Permit();
  24. }
  25.  
  26. FD1(73,void,RemDevice,struct Device *device,A1)
  27. {
  28.   Forbid();
  29.     Dev_Expunge(device);
  30.   Permit();
  31. }
  32.  
  33. FD4(74,BYTE,OpenDevice,STRPTR devName,A0,ULONG unitNumber,D0,struct IORequest *iORequest,A1,ULONG flags,D1)
  34. {
  35.   struct Device *dev;
  36.   BYTE ret=IOERR_OPENFAIL;
  37.   Forbid();
  38.     dev=(struct Device *)FindName(&SysBase->DeviceList,devName);
  39.     if(dev)
  40.     {
  41.       iORequest->io_Error=0;
  42.       iORequest->io_Device=dev;
  43.       iORequest->io_Flags=flags;
  44.       iORequest->io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  45.       Dev_Open(dev,iORequest,unitNumber,flags);
  46.       if((ret=iORequest->io_Error)!=NULL)
  47.         iORequest->io_Device=NULL;
  48.     }
  49.   Permit();
  50.   return ret;
  51. }
  52.  
  53. FD1(75,void,CloseDevice,struct IORequest *iORequest,A1)
  54. {
  55.   Forbid();
  56.     if(iORequest->io_Device)
  57.     {
  58.       Dev_Close(iORequest->io_Device,iORequest);
  59.       iORequest->io_Device=NULL;
  60.     }
  61.   Permit();
  62. }
  63.  
  64. FD1(77,void,SendIO,struct IORequest *iORequest,A1)
  65. {
  66.   iORequest->io_Flags=0;
  67.   iORequest->io_Message.mn_Node.ln_Type=0;
  68.   Dev_BeginIO(iORequest->io_Device,iORequest);
  69. }
  70.  
  71. FD1(78,struct IORequest *,CheckIO,struct IORequest *iORequest,A1)
  72. {
  73.   if(!(iORequest->io_Flags&IOF_QUICK)&&iORequest->io_Message.mn_Node.ln_Type==NT_MESSAGE)
  74.     return NULL; /* Still in use */
  75.   else
  76.     return iORequest;
  77. }
  78.  
  79. FD1(79,BYTE,WaitIO,struct IORequest *iORequest,A1)
  80. {
  81.   while(!CheckIO(iORequest))
  82.     Wait(1<<iORequest->io_Message.mn_ReplyPort->mp_SigBit);
  83.   if(iORequest->io_Message.mn_Node.ln_Type==NT_REPLYMSG)
  84.   {
  85.     Disable(); /* Cannot use GetMsg() - there may be other messages pending */
  86.       Remove(&iORequest->io_Message.mn_Node);
  87.     Enable();
  88.   }
  89.   return iORequest->io_Error;
  90. }
  91.  
  92. FD1(80,void,AbortIO,struct IORequest *iORequest,A1)
  93. {
  94.   Dev_AbortIO(iORequest->io_Device,iORequest);
  95. }
  96.  
  97. FD1(76,BYTE,DoIO,struct IORequest *iORequest,A1)
  98. {
  99.   iORequest->io_Flags=IOF_QUICK;
  100.   iORequest->io_Message.mn_Node.ln_Type=0;
  101.   Dev_BeginIO(iORequest->io_Device,iORequest);
  102.   if(!(iORequest->io_Flags&IOF_QUICK))
  103.     WaitIO(iORequest);
  104.   return iORequest->io_Error;
  105. }
  106.  
  107. FD2(109,struct IORequest *,CreateIORequest,struct MsgPort *ioReplyPort,A0,ULONG size,D0)
  108. {
  109.   struct IORequest *ret=NULL;
  110.   if(ioReplyPort&&(ret=(struct IORequest *)AllocMem(size,MEMF_PUBLIC|MEMF_CLEAR)))
  111.   {
  112.     ret->io_Message.mn_ReplyPort=ioReplyPort;
  113.     ret->io_Message.mn_Length=size;
  114.   }
  115.   return ret;
  116. }
  117.  
  118. FD1(110,void,DeleteIORequest,struct IORequest *ioReq,A0)
  119. {
  120.   if(ioReq)
  121.     FreeMem(ioReq,ioReq->io_Message.mn_Length);
  122. }
  123.  
  124. /* Not really in exec.library but we must do it anyway */
  125. void BeginIO(struct IORequest *ioReq)
  126. {
  127.   Dev_BeginIO(ioReq->io_Device,ioReq);
  128. }
  129.